package com.vcolco.utils;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.groups.Default;
import java.util.Set;

public class



ValidationUtils<T> {
    private static Validator validator = Validation.buildDefaultValidatorFactory().getValidator();

    public void validate(T data) throws RuntimeException{
        Set<ConstraintViolation<T>> violations = validator.validate(data, Default.class);
        if (null != violations && violations.size() > 0){
            violations.forEach(vi ->{
                throw new RuntimeException(vi.getMessage());
            });
        }
    }

}
